<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Supplier extends MX_Controller {
    
  function __construct() {  
    $this->load->library('template');
    $this->load->library('form_eksternal');
    $this->load->library('global_models');
    $this->load->library('PHPExcel');
    $this->load->library('encrypt');
    $this->load->helper('path');
    $this->load->helper('url');
    $this->load->model('supplier/msupplier');
    $this->load->library('parser');
    $this->load->library('session');
    $this->load->library('form_validation');
    $this->load->library('pagination');
    $this->load->library('manimage');
    $this->load->library('upload');
    $this->menu = $this->cek();
  }
  public function add_new($id = 0, $pesan = "hal"){
      //
 // echo $tes = $_FILES['image_1']['name']; exit;
   
            
      //   echo   $this->upload->display_errors(); exit;

    $this->template->title('Sistem', "Add Edit");
   
    if($id > 0){
      $data_detail = $this->global_models->get("m_supplier", array("id_supplier" => $id));

    }
    else{
      $data_detail[0]->id_supplier = 0;
      $data_detail[0]->title = "";
    }
    if(!$this->input->post(NULL, TRUE)){
      $this->template->build('add-new-master-supplier', 
        array('message' => $pesan,
              'url'     => base_url()."themes/srabon/",
              'title'   => 'Add Master Supplier',
              'detail'  => $data_detail,
              'menu_drop'   => $this->menu,
              'menu'        => "settings",
         
            ));
      $this->template
        ->set_layout('default')
        ->build('add-new-master-supplier');
    }
    else{
      if($this->input->post("id_detail", TRUE)){
      
        $kirim = array(
              "title"                  =>  $this->input->post("title", TRUE),
              "pic"                  =>  $this->input->post("pic", TRUE),
              "email"                  =>  $this->input->post("email", TRUE),
              "telp"                  =>  $this->input->post("telp", TRUE),
              "alamat"                  =>  $this->input->post("alamat", TRUE),
              "update_by_users"       =>  $this->session->userdata('id')
          );
        $hasil_in = $this->global_models->update("m_supplier", array("id_supplier" => $this->input->post("id_detail", TRUE)), $kirim);
        if($hasil_in){
          redirect ("supplier/index/list/sukses");
        }
        else
          redirect ("supplier/index/list/filed");
      }
      else{
        $pst = $this->input->post(NULL, TRUE);
//        $pst = $pst['addressform']['addressform'][0];
        if($pst['title']){
          $kirim = array(
              "title"                  =>  $this->input->post("title", TRUE),
              "pic"                  =>  $this->input->post("pic", TRUE),
              "email"                  =>  $this->input->post("email", TRUE),
              "telp"                  =>  $this->input->post("telp", TRUE),
              "alamat"                  =>  $this->input->post("alamat", TRUE),
              "create_by_users"       =>  $this->session->userdata('id'),
              "create_date"           =>  date("Y-m-d H:i:s"),
              "update_by_users"       =>  $this->session->userdata('id')
          );
       
          if($this->global_models->insert("m_supplier", $kirim))
            redirect ("supplier/index/list/sukses");
          else{
            redirect ("supplier/index/list/filed");
          }
        }
        else{
          redirect ("supplier/index/list/filed");
        }
      }
    }
  }
  
  /**
   * ini delete
   * @param int $id id yang didelete
   * @return true redirect
   * @
   */
	public function delete($id){
    if($this->global_models->delete("m_supplier", array("id_supplier" => $id)))
      redirect("supplier/index/list/");
    else
      redirect("supplier/index/list/");
  }
	public function export_xls(){
    $this->msupplier->export_xls("data-supplier");
  }
public function index($action = "list", $pesan = "hal", $hal = 0){
    $list = $this->msupplier->get("id_supplier","m_supplier");
    
    $this->template->title('Sistem', "Master Supplier");
     
//    
    $this->template->build('main', 
      array('message'     => $pesan,
            'url'         => base_url()."themes/srabon/",
            'data'        => $list,
            'menu_drop'   => $this->menu,
            'menu'        => "settings",
            'title_table' => "Menu Master Supplier",
            'foot'        => ""
          ));
    $this->template
      ->set_layout('default')
      ->build('main');
	}
  
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */